﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utilities;
using InfoSoftGlobal;

public partial class OnTime : System.Web.UI.Page 
{

    private struct TaskProgress
    {
        public string WebName;
        public int ProgressCount;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FCLiteral.Text = CreateTaskOnTimeChart();

       
    }

    public string CreateTaskOnTimeChart()
    {
        string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetTaskProgress", con);

        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        con.Open();

        System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
        System.Collections.ArrayList tasks = new System.Collections.ArrayList();

        while (dr.Read())
        {
            TaskProgress task = new TaskProgress();
            task.WebName = (string)dr["WebName"];
            task.ProgressCount = (int)dr["Progress"];

            tasks.Add(task);
        }

        con.Close();

        string strXML; int i;

        //strXML = "<graph caption='Breakdown of Project Status' subCaption='(into Products and Services)' xAxisName='Project' yAxisMaxValue='5' numberSuffix='%' areaBorderColor='FFFFFF' showValues='0' numVDivLines='6' palette='5'>";
        strXML = "<graph caption='Tasks On-Time Progress' numberPrefix='%' xAxisName='Resources' yAxisMaxValue='100' decimalPrecision='0' areaBorderColor='FFFFFF' showValues='0' numVDivLines='10' palette='5'>";

        for (i = 0; i < tasks.Count; i++)
        {
            TaskProgress task = (TaskProgress)tasks[i];
            if (task.ProgressCount > 74)
                strXML += "<set name='" + task.WebName + "' value='" + task.ProgressCount.ToString() + "' color='006F00' />";
            else
                strXML += "<set name='" + task.WebName + "' value='" + task.ProgressCount.ToString() + "' color='FF0000' />";
        }

        strXML += "</graph>";

        //Create the chart - Column 3D Chart with data contained in strXML
        return FusionCharts.RenderChart("../FusionCharts/FCF_Column3D.swf", "", strXML, "productSales", "450", "300", false, false);


    }


}
